package org.example.carsystem.config;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.metadata.data.WriteCellData;

public class StatusConverter implements Converter<String> {

    @Override
    public Class supportJavaTypeKey() {
        // 支持的Java类型，这里是Integer类型
        return String.class;
    }
    @Override
    public String convertToJavaData(ReadConverterContext context) {
        String str = context.getReadCellData().getStringValue();
        if ("正常".equals(str)) {
            return "0";
        } else if ("停用".equals(str)) {
            return "1";
        }else {
            return null; // 或者根据实际情况返回其他值，比如默认值
        }
    }
    @Override
    public WriteCellData convertToExcelData(WriteConverterContext<String> context) {
        if (context.getValue() == null) {
            return new WriteCellData("");
        } else if (context.getValue().equals("1")) {
            return new WriteCellData("停用");
        } else if (context.getValue().equals("0")) {
            return new WriteCellData("正常");
        } else {
            return new WriteCellData("未知");
        }
    }
}
